<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>PostManage</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="author" content="Yangliu449" />
    <link href="assets/css/icons.css" rel="stylesheet" />
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
    <link href="assets/css/main.css" rel="stylesheet" />
    <link href="easyui.css" rel="stylesheet" />
    <link href="icon.css" rel="stylesheet" />
    <script src="jquery-3_2_1.js" ></script>
    <script src="jquery_easyui_min.js" ></script>
    <meta name="msapplication-TileColor" content="#3399cc"/>
</head>
<body>
<!-- Start #header -->
<div id="header">
    <div class="container-fluid">
        <div class="navbar">
            <div class="navbar-header">
                <a class="navbar-brand" href="#" id="indexShow" >
                    <i class="im-windows8 text-logo-element animated bounceIn"></i><span class="text-logo">hr</span><span class="text-slogan">ms</span>
                </a>
            </div>
            <nav class="top-nav" role="navigation">
                <ul class="nav navbar-nav pull-right">
                    <li class="dropdown">
                        <a href="#" id="username" >
                            <img class="user-avatar" src="assets/img/avatars/48.jpg" alt="userName">userName</a>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
</div>
<!-- End #header -->
<!-- Start #sidebar -->
<div id="sidebar">
    <!-- Start .sidebar-inner -->
    <div class="sidebar-inner">
        <!-- Start #sideNav -->
        <ul id="sideNav" class="nav nav-pills nav-stacked">
            <li class="top-search">
                <form>
                    <input type="text" name="search" placeholder="Search ...">
                    <button type="submit"><i class="ec-search s20"></i>
                    </button>
                </form>
            </li>
            <li><a href="index.html">Department Manage <i class="im-screen"></i></a>
            </li>
            <li><a href="charts.html">Position Manage<i class="st-chart"></i></a>
            </li>
            <li>
                <a href="data-tables.html">Employee Manage <i class="im-paragraph-justify"></i></a>
            </li>
            <li>
                <a href="data-tables.html" id="postManage">Post Manage <i class="im-table2"></i></a>
            </li>
            <li>
                <a href="#"><i class="st-files " id="adminManage" ></i>Admin Manage</a>
            </li>
            <li>
                <a href="#"><i class="en-upload "></i>Exit Hrms</a>
            </li>

        </ul>
    </div>
</div>

<!-- Start #content -->
<div id="content">
    <!-- Start .content-wrapper -->
    <div class="content-wrapper">
        <div class="row">
            <!-- Start .row -->
            <!-- Start .page-header -->
            <div class="col-lg-12 heading">
                <h1 class="page-header"><i class="im-screen"></i>欢迎使用HRMS</h1>
                <!-- Start .bredcrumb -->
                <ul id="crumb" class="breadcrumb">
                </ul>
                <!--开始编写表格代码-->
                <table id="dg_post" class="easyui-datagrid" title="Post Show"
                       data-options="singleSelect:true,collapsible:true,method:'get'">
                    <thead>
                    <tr>
                        <th data-options="field:'id',width:80">编号</th>
                        <th data-options="field:'title',width:100">标题</th>
                        <th data-options="field:'content',width:80,align:'right'">内容</th>
                        <th data-options="field:'date',width:80,align:'right'" datatype="date">创建日期</th>
                        <th data-options="field:'createname',formatter:function(value, rec){ return rec.admin.username;}, width:80,align:'right'">创建人</th>
                    </tr>
                    </thead>
                </table>
                <!--定义Admin显示表格工具栏-->
                <div id="tb_tool" style="padding:5px;height:auto">
                    <div style="margin-bottom:5px">
                        <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newPost()"></a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editPost()"></a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deletePost()"></a>
                    </div>
                </div>

                <!--学生信息form表单 以及弹窗的定义-->
                <div id="dlg_post" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
                     closed="true" buttons="#dlg-buttons">
                    <div style="color: skyblue">公告信息</div><hr />
                    <form id="form_post">
                        <table cellpadding="5">
                            <tr>
                                <td>ID:</td>
                                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="number" name="id" id="id" ></td>
                            </tr>
                            <tr>
                                <td>标题:</td>
                                <td><input class="easyui-textbox"  style="width: 100px;height:32px" type="text" name="title" id="title"  data-options="required:true"></td>
                            </tr>
                            <tr>
                                <td>内容：</td>
                                <td><input  class="easyui-textbox"  style=" width:100%; height:32px" type="text" name="content"  data-options="required:true"></td>
                            </tr>
                            <tr>
                                <td>创建日期：</td>
                                <td><input class="easyui-textbox" style="width:100%;height:32px"  type="date" name="date" id="date" ></td>
                            </tr>
                            <tr>
                                <td>创建人：</td>
                                <td><input class="easyui-textbox" style="width:100%;height:32px"  type="text" name="createname" id="createname" ></td>
                            </tr>
                        </table>
                    </form>
                    <div id="dlg-buttons">
                        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="savePost()">确认</a>
                        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg_post').dialog('close')">取消</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    <!--获取地址栏参数-->
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    // 调用获取地址栏参数的方法
    var username =GetQueryString("username");
    if(username!=null && username.toString().length>1)
    {
        console.log(username);
    }

    //更改用户名
    var adminUrl = "/adminShow?username="+username;
    var postUrl = '/showPost?username='+username;
    var indexUrl = "/showIndex?username"+username;
    $(document).ready(function(){
        $("#username").html("<img class=\"user-avatar\" src=\"assets/img/avatars/48.jpg\" alt=\"SuggeElson\"></a>"+username);
        $("#adminManage").attr('href',adminUrl);
        $("#postManage").attr('href',postUrl);
        $("#indexShow").attr('href',indexUrl);
    });


    //表格初始化
    $("#dg_post").datagrid({
        url:"/postData",
        singleSelect:true,
        rownumbers:"true",
        fitColumns:"true",
        toolbar:'#tb_tool',});

    var url = "#";
    //    管理员工具栏函数实现
    function newPost(){
        $("#dlg_post").dialog('open').dialog('setTitle','NewPost');
        $("#form_post").form('clear');
        $("#id").textbox('readonly',true);
        url = '/addPost';
    }
    function editPost() {
        var row = $("#dg_post").datagrid('getSelected');
        console.log(row);

        if(row){
            $("#dlg_post").dialog('open').dialog('setTitle','EditPost');
            $("#id").textbox('readonly',false);
            $("#form_post").form('load',{
                id:row.id,
                title:row.title,
                content:row.content,
                date:row.date,
                createname:row.admin.username
            });
            url  = '/updatePost';
        }
    }
    function deletePost(){
        var row = $("#dg_post").datagrid('getSelected');
        if(row){
            $.messager.confirm('Confirm','你确定要删除这个公告吗？',function (r) {
                if(r){
                    $.post('/deletePost',row,function (result) {
                        $("#dg_post").datagrid('reload');
                    });
                }
            });
        }
    }
    function savePost() {
        $("#form_post").form('submit',{
            url:url,
            success:function (result) {
                $("#dlg_post").dialog('close');
                $("#dg_post").datagrid('reload');
                console.log(result);
            }
        });
    }

</script>

</body>
</html>